<?php

/* 商品规格 goodsspec */
class GoodsspecModel extends BaseModel
{
    var $table  = 'goods_spec';
    var $prikey = 'spec_id';
    var $alias  = 'gs';
    var $_name  = 'goodsspec';

    var $_relation  = array(
        // 一个商品规格只能属于一个商品
        'belongs_to_goods' => array(
            'model'         => 'goods',
            'type'          => BELONGS_TO,
            'foreign_key'   => 'goods_id',
            'reverse'       => 'has_goodsspec',
        ),
        'belongs_to_ordergoods' => array(
            'model'         => 'goods',
            'type'          => BELONGS_TO,
            'foreign_key'   => 'spec_id',
            'reverse'       => 'has_to_goodsspec',
        ),
        'spec_wish' => array(
            'model'         => 'wish',
            'type'          => HAS_MANY,
            'foreign_key'   => 'spec_id',
            'dependent' => true, // 依赖
        ),
        'has_cart_items' => array(
            'model'         => 'cart',
            'type'          => HAS_MANY,
            'foreign_key'   => 'spec_id',
        ),
        //		lichen 2019/4/15 end
        // 商品规格只能有一个商家库存
        'has_storestock' => array(
            'model' => 'storestock',
            'type' => HAS_MANY,
            'foreign_key' => 'storestock_id',
            'dependent' => true
        ),
//		lichen 2019/4/15 end
    );

    function getInfo($goods_id){
        $spec_mod = & m('goodsspec');
        $sql = "SELECT * FROM ecmall.ecm_goods_spec WHERE goods_id=".$goods_id ." GROUP By spec_3value";
        return $this->db->getAll($sql);
    }
    function getSpecStockInfo($goods_id){
        $spec_mod = & m('goodsspec');
        $sql = "SELECT * FROM ecmall.ecm_goods_spec LEFT JOIN ecm_storestock on ecm_goods_spec.spec_3value = ecm_storestock.storestock_id WHERE goods_id=".$goods_id;
        return $this->db->getAll($sql);
    }
}


?>